;
;  PROGRAM:  WHEEL
;  VERSION:  1.1
;  AUTHOR:  RICHARD CONN
;  DATE:  24 JAN 83
;  PREVIOUS VERSIONS:  1.0 (14 Jan 83)
;
vers	equ	11

;
;	WHEEL is used to set and clear the WHEEL byte.  It is invoked by
; one of the following forms:
;
;		WHEEL or WHEEL //	<-- Print Help
;		WHEEL password SET	<-- Set Wheel Byte
;		WHEEL password		<-- Set Wheel Byte
;		WHEEL password RESET	<-- Reset (Clear) Wheel Byte
;		WHEEL /S or WHEEL /R	<-- Set or Reset Wheel Byte
;						(Type Password Later Sans Echo)
;

;
;  CP/M Constants
;
cpm	equ	0
bdose	equ	cpm+5
pass	equ	cpm+5dh	; 1st FCB is password
cmnd	equ	cpm+6dh	; 2nd FCB is command
tbuff	equ	cpm+80h
cr	equ	0dh
lf	equ	0ah

;
;  SYSLIB Routines
;
	ext	print,caps,codend,inline

;
;	This program is Copyright (c) 1982, 1983 by Richard Conn
;	All Rights Reserved
;
;	ZCPR2 and its utilities, including this one, are released
; to the public domain.  Anyone who wishes to USE them may do so with
; no strings attached.  The author assumes no responsibility or
; liability for the use of ZCPR2 and its utilities.
;
;	The author, Richard Conn, has sole rights to this program.
; ZCPR2 and its utilities may not be sold without the express,
; written permission of the author.
;

;
;  Branch to Start of Program
;
	jmp	start

;
;******************************************************************
;
;  SINSFORM -- ZCPR2 Utility Standard General Purpose Initialization Format
;
;	This data block precisely defines the data format for
; initial features of a ZCPR2 system which are required for proper
; initialization of the ZCPR2-Specific Routines in SYSLIB.
;

;
;  EXTERNAL PATH DATA
;
EPAVAIL:
	DB	0FFH	; IS EXTERNAL PATH AVAILABLE? (0=NO, 0FFH=YES)
EPADR:
	DW	40H	; ADDRESS OF EXTERNAL PATH IF AVAILABLE

;
;  INTERNAL PATH DATA
;
INTPATH:
	DB	0,0	; DISK, USER FOR FIRST PATH ELEMENT
			; DISK = 1 FOR A, '$' FOR CURRENT
			; USER = NUMBER, '$' FOR CURRENT
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0	; DISK, USER FOR 8TH PATH ELEMENT
	DB	0	; END OF PATH

;
;  MULTIPLE COMMAND LINE BUFFER DATA
;
MCAVAIL:
	DB	0FFH	; IS MULTIPLE COMMAND LINE BUFFER AVAILABLE?
MCADR:
	DW	0FF00H	; ADDRESS OF MULTIPLE COMMAND LINE BUFFER IF AVAILABLE

;
;  DISK/USER LIMITS
;
MDISK:
	DB	4	; MAXIMUM NUMBER OF DISKS
MUSER:
	DB	31	; MAXIMUM USER NUMBER

;
;  FLAGS TO PERMIT LOG IN FOR DIFFERENT USER AREA OR DISK
;
DOK:
	DB	0FFH	; ALLOW DISK CHANGE? (0=NO, 0FFH=YES)
UOK:
	DB	0FFH	; ALLOW USER CHANGE? (0=NO, 0FFH=YES)

;
;  PRIVILEGED USER DATA
;
PUSER:
	DB	10	; BEGINNING OF PRIVILEGED USER AREAS
PPASS:
	DB	'chdir',0	; PASSWORD FOR MOVING INTO PRIV USER AREAS
	DS	41-($-PPASS)	; 40 CHARS MAX IN BUFFER + 1 for ending NULL

;
;  CURRENT USER/DISK INDICATOR
;
CINDIC:
	DB	'$'	; USUAL VALUE (FOR PATH EXPRESSIONS)

;
;  DMA ADDRESS FOR DISK TRANSFERS
;
DMADR:
	DW	80H	; TBUFF AREA

;
;  NAMED DIRECTORY INFORMATION
;
NDRADR:
	DW	00000H	; ADDRESS OF MEMORY-RESIDENT NAMED DIRECTORY
NDNAMES:
	DB	64	; MAX NUMBER OF DIRECTORY NAMES
DNFILE:
	DB	'NAMES   '	; NAME OF DISK NAME FILE
	DB	'DIR'		; TYPE OF DISK NAME FILE

;
;  REQUIREMENTS FLAGS
;
EPREQD:
	DB	000H	; EXTERNAL PATH?
MCREQD:
	DB	000H	; MULTIPLE COMMAND LINE?
MXREQD:
	DB	000H	; MAX USER/DISK?
UDREQD:
	DB	000H	; ALLOW USER/DISK CHANGE?
PUREQD:
	DB	0FFH	; PRIVILEGED USER?
CDREQD:
	DB	000H	; CURRENT INDIC AND DMA?
NDREQD:
	DB	000H	; NAMED DIRECTORIES?
Z2CLASS:
	DB	8	; CLASS 8
	DB	'ZCPR2'
	DS	10	; RESERVED

;
;  END OF SINSFORM -- STANDARD DEFAULT PARAMETER DATA
;
;******************************************************************
;

;
;  Special Value
;
WHLADR:
	DW	0	; ADDRESS OF WHEEL BYTE

;
;  Start of Program
;
start:
	call	print
	db	'WHEEL  Version '
	db	vers/10+'0','.',(vers mod 10)+'0',0

	lda	pass	; get password
	cpi	' '	; help?
	jz	help
	cpi	'/'
	jnz	start1
	lda	pass+1	; get option
	sta	cmnd	; store command
	cpi	'R'	; reset?
	jz	inpass
	cpi	'S'	; Set?
	jz	inpass
help:
	call	print
	db	cr,lf,'	WHEEL is used to Set and Reset (Clear) the Wheel'
	db	cr,lf,'Byte in order to enable (Wheel Byte is Set) or disable'
	db	cr,lf,'(Wheel Byte is Reset) certain commands within ZCPR2.'
	db	cr,lf
	db	cr,lf,'The forms of the WHEEL command are:'
	db	cr,lf,'	WHEEL or WHEEL //	<-- Print Help'
	db	cr,lf,'	WHEEL password SET	<-- Set Wheel Byte'
	db	cr,lf,'	WHEEL password		<-- Set Wheel Byte'
	db	cr,lf,'	WHEEL password RESET	<-- Reset (Clear) Wheel Byte'
	db	cr,lf,'	WHEEL /S or WHEEL /R	<-- Set or Reset Wheel Byte'
	db	cr,lf,'					but allow user to type'
	db	' in password'
	db	cr,lf,'					without echo'
	db	cr,lf,0
	ret

;
;  Input Password without echo and then process it
;
inpass:
	call	print
	db	cr,lf,'Password? ',0
	call	codend	; pt to scratch area
	xra	a	; no echo
	call	inline	; get line from user
	push	h	; save ptr to first char
inp1:
	mov	a,m	; capitalize input
	call	caps
	mov	m,a
	inx	h	; pt to next
	ora	a	; done?
	jnz	inp1
	pop	h	; get ptr to first char
	jmp	start2
;
;  Process Password
;
start1:
	lxi	h,pass	; pt to user password
start2:
	lxi	d,ppass	; pt to WHEEL password
	mvi	b,8	; 8 chars max
passlp:
	ldax	d	; get WHEEL password
	ora	a	; done?
	jz	passtst
	call	caps	; capitalize
	cmp	m	; match?
	jnz	nopass
	inx	h	; pt to next
	inx	d
	dcr	b	; count down
	jnz	passlp
	jmp	passit
passtst:
	mov	a,m	; must be space or null
	ora	a	; null?
	jz	passit
	cpi	' '
	jnz	nopass
passit:
	lhld	whladr	; get address of wheel byte
	lda	cmnd	; check command
	cpi	'R'	; reset?
	jz	reset
	mvi	m,0ffh	; set wheel byte
	call	print
	db	cr,lf,'WHEEL Byte Set',0
	ret
reset:
	mvi	m,0	; reset wheel byte
	call	print
	db	cr,lf,'WHEEL Byte Reset',0
	ret
nopass:
	call	print
	db	cr,lf,'Invalid Password',0
	ret

	end
